package com.badlogic.androidgames.game;

import android.graphics.Color;
import android.graphics.Rect;

import com.badlogic.androidgames.framework.Graphics;
import com.badlogic.androidgames.framework.Pixmap;

public class GameObject {
	
	Pixmap tex;
	Vector2 pos, srcPos;
	Vector2 size, srcSize;
	Rect rectangle, srcRect;
	
	public GameObject(Pixmap tex, Vector2 pos, Vector2 size)
	{
		this.tex = tex;
		this.pos = pos;
		this.srcPos = new Vector2(0, 0);
		this.srcSize = this.size = size;
		
		srcRect = new Rect((int)srcPos.x, 
						   (int)srcPos.y, 
						   (int)(srcPos.x + srcSize.x), 
						   (int)(srcPos.y + srcSize.y));
		
		UpdateBounds();
		
	}
	
	public GameObject(Pixmap tex, Vector2 pos, Vector2 size, Vector2 srcPos, Vector2 srcSize)
	{
		this.tex = tex;
		this.pos = pos;
		this.size = size;
		this.srcPos = srcPos;
		this.srcSize = srcSize;
		
		srcRect = new Rect((int)srcPos.x, 
				   		   (int)srcPos.y, 
				   		   (int)(srcPos.x + srcSize.x), 
				   		   (int)(srcPos.y + srcSize.y));
		
		UpdateBounds();
	}
	
	public void Update()
	{
	}
	
	public void MoveX(float newX)
	{
		pos.x += newX;
		UpdateBounds();
	}
	
	public void MoveY(float newY)
	{
		pos.y += newY;
		UpdateBounds();
	}
	
	public void Move(float newX, float newY)
	{
		pos.x += newX;
		pos.y += newY;
		UpdateBounds();
	}
	
	public void UpdateBounds()
	{
		rectangle = new Rect((int)pos.x, 
							 (int)pos.y, 
							 (int)pos.x + (int)size.x, 
							 (int)pos.y + (int)size.y);
	}
	
	public void Draw(Graphics g)
	{
		g.drawPixmap(tex, (int)pos.x, (int)pos.y, 
						  (int)size.x, (int)size.y, 
					      srcRect.left, srcRect.top, 
					      srcRect.width(), srcRect.height(), Color.WHITE);
	}
	
	public void Draw(Graphics g, int color)
	{
		g.drawPixmap(tex, (int)pos.x, (int)pos.y, 
				  		  (int)size.x, (int)size.y, 
				  		  srcRect.left, srcRect.top, 
				  		  srcRect.width(), srcRect.height(), color);
	}
}
